package com.yxb.cms.service;

import com.yxb.cms.architect.constant.BussinessCode;
import com.yxb.cms.architect.utils.BussinessMsgUtil;
import com.yxb.cms.architect.utils.DateUtil;
import com.yxb.cms.dao.CoursesMapper;
import com.yxb.cms.dao.EvaluateTeachMapper;
import com.yxb.cms.dao.StuCourseMapper;
import com.yxb.cms.dao.expmle.StuCourseExample;
import com.yxb.cms.domain.bo.BussinessMsg;
import com.yxb.cms.domain.vo.Courses;
import com.yxb.cms.domain.vo.EvaluateTeach;
import com.yxb.cms.domain.vo.StuCourse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.nutz.json.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 
 */
@Service
public class EvaluateTeachService {
    private Logger log = LogManager.getLogger(EvaluateTeachService.class);

    @Autowired
    private EvaluateTeachMapper evaluateTeachMapper;

    @Transactional
    public BussinessMsg insertStudents(EvaluateTeach evaluateTeach){

        try {
            evaluateTeachMapper.insertSelective(evaluateTeach);
        } catch (Exception e) {
            log.error("保存学生信息方法内部错误",e);
            throw e;
        }
        return BussinessMsgUtil.returnCodeMessage(BussinessCode.GLOBAL_SUCCESS);
    }


    /**
     * 删除学生
     * @param stuId 学生ID
     */
    @Transactional
    public BussinessMsg deleteByPrimaryKeySelective(Long evaluateId){
        try {
            evaluateTeachMapper.deleteByPrimaryKey(evaluateId);
        } catch (Exception e) {
            log.error("删除学生信息方法内部错误",e);
            throw e;
        }
        return BussinessMsgUtil.returnCodeMessage(BussinessCode.GLOBAL_SUCCESS);
    }


    public String selectStuCoursePageList(EvaluateTeach evaluateTeach,String userName){
        if(userName=="超级管理员" || userName.equals("超级管理员")){
            System.out.print("TEST SUCCESS");
            userName=null;
        }
        List<EvaluateTeach> stuCourses = evaluateTeachMapper.selectEvaluateTeachPage(evaluateTeach,userName);

        Long count = evaluateTeachMapper.count(evaluateTeach);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data", stuCourses);
        return Json.toJson(map);
    }



}